package cn.rose.test;
/**
 * @FileName StringUtils.java
 * @Description: 
 * @author rose
 * @version 1.0
 * <p>Company: OYESGO</p>
 * <p>Copyright: Copyright (c) 2010</p>
 */
public class StringUtils {
//	private static ResourceBundle bundle ;
	
//	static{
//		if (bundle == null) {
//			//下面的message就是你在src下资源文件的名字
//			//即src下面自己建立的messages.properties
//			//表示加载资源文件
//			bundle = ResourceBundle.getBundle("messages");
//		}
//	}
	
//	/**
//	 *  传入资源文件中的键获得其对应的�??
//	 * @param key 资源文件中你设定的key
//	 * @return
//	 */
//	public static String getPropertiesMsg(String key){
//		String result = "";
//		if (key ==null || "".equals(key)) {
//			return result;
//		}else {
//			key = key.trim();
//		}
//		try {
//			result = bundle.getString(key);
//		} catch (Exception e) {
//			result = "";
//			System.out.println("exception:获取资源文件数据异常");
//		}
//		return result;
//	}
	/**
	 * 传入字符�? 按照某个 字符 截取字符�? 返回String数组
	 * @param str �?要处理的字符�?
	 * @param tag 按照tag截取
	 * @return
	 */
	public static String[] splitByTag(String str,String tag){
		String[] result = null;
		if (str == null || "".equals(str) || tag == null || "".equals(tag)) {
			return result;
		}else {
			str = str.trim();
		}
		
		try {
			result = str.split(tag+"+");
		} catch (Exception e) {
			result = null;
			System.out.println("exception:截取出现异常");
		}
		return result;
	}
	/**
	 * String 类型转换 int 类型
	 * @param str
	 * @return
	 */
	public static int getInt(String str){
		if (str == null || "".equals(str)) {
			return 0;
		}else {
			str = str.trim();
		}
		int n = 0;
		try {
			n = Integer.parseInt(str);
		} catch (Exception e) {
			n = 0;
			System.out.println("exception:类型转换异常");
		}
		return n;
	}
	
	/**
	 * String 类型转换 double 类型
	 * @param str
	 * @return
	 */
	public static double getDouble(String str){
		if (str == null || "".equals(str)) {
			return 0;
		}else {
			str = str.trim();
		}
		double n = 0;
		try {
			n = Double.parseDouble(str);
		} catch (Exception e) {
			n = 0;
			System.out.println("exception:类型转换异常");
		}
		return n;
	}
	/**
	 * 格式化字符串去除首尾空格以及防止空指针异�?
	 * @param str
	 * @return
	 */
	public static String getString(Object str){
		String result = "";
		
		if (str != null && !"".equals(str)) {
			result = str.toString().trim();
		}
		return result;
	}
	/**
	 * 判断字符串是否为空�??
	 * @param str
	 * @return
	 * boolean
	 * @author rose
	 */
	public static boolean isEmpty(Object object){
		return object == null || "".equals(object.toString().trim());
	}
	/**
	 * 邮件发�?�模�?
	 * @param title html的标�?
	 * @param content 邮件内容
	 * @param name 对方称呼 群发时�?�可以写�? ""
	 * @return String 完整的html格式的邮件内�?
	 * @author rose
	 */
	public static String mailModel(String title,String content,String name){
		StringBuffer modelSb = new StringBuffer();
		modelSb.append("<html><head><title>");
		modelSb.append(title);
		modelSb.append("</title></head>");
		modelSb.append("<body style='margin:20px 0 10px; font-size:12px; text-align:center; background:#CCECEC'>");
		modelSb.append("<div style='width:600px; margin:0 auto; text-align:left; padding:30px; background:#fff; border:1px'>");
		modelSb.append("<div style='background:#EAF3FA;'>");
		modelSb.append("</div>");
		modelSb.append("<div style='margin:6px 0 0; padding:0 5px'>");
		modelSb.append("<p>你好�?");
		modelSb.append(name);
		modelSb.append("<br>");
		modelSb.append("<span class='normal_orange14'>");
		modelSb.append(content);
		modelSb.append("</span></p>");
		modelSb.append("</div><hr/>");
		modelSb.append("<div><p style='line-height:150%'><font color='#0000FF'>供应商管�?</font>&nbsp;|&nbsp;<font color='#0000FF'>机票供应商模�?</font>&nbsp;|&nbsp;<font color='#0000FF'>供应商基�?信息</font><br/></p></div>");
		modelSb.append("<div><p>&gt;&gt;<a href='http://oa.oyesgo.net/'>登录OA管理系统</a></p></div>");
		modelSb.append("<divs tyle='margin:41px 0 0;padding:0 5px;line-height:18px;'><div style='margin:5px 3px 0 0;padding:0 5px;background:#EAF3FA;border-collapse:collapse;font-size:12px;color:#6B6B6B'>http://oa.oyesgo.net&nbsp;&nbsp;&nbsp;</div></div></div></body></html>");
		return modelSb.toString();
	}
	/**
	 * 获取n位随即码
	 * @param n
	 * @return
	 * String
	 * @author rose
	 */
	public static String getRandomStr(int n){
		String[] strSource = {
				"A", "B", "C", "D", "E", "F", "G", "H", "b", "c", "x",
				"y", "N", "O", "P", "s", "t", "u", "v", "w", "d", "e", 
				"f", "g", "3", "4", "5", "6", "7", "8", "9", "0", "1", 
				"2", "z", "Z", "a", "I", "J", "K", "L", "M", "h", "i", 
				"j", "k", "l", "m", "Y", "n", "o", "p", "q", "r", "Q", 
				"R", "S", "T", "U", "V", "W", "X"
		};
		StringBuffer sb = new StringBuffer();
		//生成n位随机码
		for (int i = 0; i < n; i++) {
			int j = (int)(Math.random()*strSource.length);
			if(j == 0) sb.append(strSource[j]);
			else sb.append(strSource[j-1]);
		}
		return sb.toString();
	}
	public static void main(String[] args) {
		System.out.println(getRandomStr(20));
	}
}
